import SomeoneMenu from "./SomeoneMenu";

const { ccclass, property } = cc._decorator;

@ccclass
export class TipsUI extends cc.Component {

    public lab_txt: cc.Label = null;

    onLoad() {

        this.lab_txt = this.node.getChildByName('lab_txt').getComponent(cc.Label);
    }

    start() {

    }

    onShowMove(txt: string) {

        this.lab_txt.string = txt;
        this.scheduleOnce(() => {
            this.node.destroy();
        }, 1.5);
    }
}

export class TipMag {

    public static In: TipMag = null;

    public constructor() {
        TipMag.In = this;
    }

    PopTips(Tip: string) {

        cc.resources.load('TipsUI', cc.Prefab, (error: Error, prefab: cc.Prefab) => {
            let tip = cc.instantiate(prefab);
            SomeoneMenu.Inst.node.addChild(tip);
            (tip.getComponent('TipsUI') as TipsUI).onShowMove(Tip);
        })
    }
}
